<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Pisces","version":"7.7.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="tomcat，HTTP">
<meta property="og:type" content="article">
<meta property="og:title" content="Java日拱一卒-day18">
<meta property="og:url" content="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/index.html">
<meta property="og:site_name" content="很惭愧，就做了一点微小的工作">
<meta property="og:description" content="tomcat，HTTP">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/http.png">
<meta property="og:image" content="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/http%E8%AF%B7%E6%B1%82.png">
<meta property="og:image" content="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/http%E5%93%8D%E5%BA%94.png">
<meta property="article:published_time" content="2020-05-15T15:45:43.000Z">
<meta property="article:modified_time" content="2020-05-18T02:47:58.958Z">
<meta property="article:author" content="文予">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/http.png">

<link rel="canonical" href="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Java日拱一卒-day18 | 很惭愧，就做了一点微小的工作</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">很惭愧，就做了一点微小的工作</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">念念不忘，必有回响</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day18/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/uploads/wenyu.png">
      <meta itemprop="name" content="文予">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="很惭愧，就做了一点微小的工作">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Java日拱一卒-day18
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2020-05-15 23:45:43" itemprop="dateCreated datePublished" datetime="2020-05-15T23:45:43+08:00">2020-05-15</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2020-05-18 10:47:58" itemprop="dateModified" datetime="2020-05-18T10:47:58+08:00">2020-05-18</time>
              </span>

          
            <div class="post-description">tomcat，HTTP</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="tomcat服务器"><a href="#tomcat服务器" class="headerlink" title="tomcat服务器"></a>tomcat服务器</h2><p>Tomcat是由Apache组织提供的一种web服务器，提供对jsp和Servlet的支持。它是一种轻量级的java web容器（服务器）</p>
<p>web服务器是指驻留在互联网上的某种类型的计算机程序。当浏览器访问服务器，请求服务器上的文件时，服务器会处理该请求，并将请求的文件响应给浏览器，并会附带一些信息告诉浏览器该如何查看该文件（即文件类型）</p>
<h3 id="目录介绍"><a href="#目录介绍" class="headerlink" title="目录介绍"></a>目录介绍</h3><ul>
<li>bin：专门存放Tomcat服务器的可执行程序</li>
<li>conf：存放Tomcat服务器的配置文件</li>
<li>lib：存放Tomcat的jar包</li>
<li>logs：存放Tomcat服务器产生的日志信息</li>
<li>temp：存放运行时产生的临时文件</li>
<li>webapps：用于存放部署的web工程</li>
<li>work：是Tomcat工作时的目录，用来存放Tomcat运行时jsp翻译为Servlet的源码，和Session钝化的目录。</li>
</ul>
<h3 id="启动Tomcat"><a href="#启动Tomcat" class="headerlink" title="启动Tomcat"></a>启动Tomcat</h3><ul>
<li>配置环境变量</li>
</ul>
<p>变量名：<code>JAVA_HOME</code></p>
<ul>
<li>启动、关闭tomcat服务器（以windows环境为例）</li>
</ul>
<p>启动：[tomcat根目录]\bin\startup.bat<br>关闭：[tomcat根目录]\bin\shutdown.bat</p>
<p>在tomcat启动后，服务器默认监听8080端口，可以通过一下地址访问tomcat服务器主页：</p>
<blockquote>
<p><a href="http://localhost:8080/" target="_blank" rel="noopener">http://localhost:8080/</a></p>
</blockquote>
<h3 id="修改默认端口"><a href="#修改默认端口" class="headerlink" title="修改默认端口"></a>修改默认端口</h3><p>tomcat默认监听端口为8080，可以改为80端口。因为80端口非常特殊，可以省略不写</p>
<p>修改方法：将conf目录下的server.xml文件袋第69行<code>&lt;Connector&gt;</code>标签上的<code>port</code>属性的值改为<code>80</code>即可。</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">Connector</span> <span class="attr">port</span>=<span class="string">"80"</span> <span class="attr">protocol</span>=<span class="string">"HTTP/1.1"</span></span></span><br><span class="line"><span class="tag">           <span class="attr">connectionTimeout</span>=<span class="string">"20000"</span></span></span><br><span class="line"><span class="tag">           <span class="attr">redirectPort</span>=<span class="string">"8443"</span> /&gt;</span></span><br></pre></td></tr></table></figure>

<p>改完之后，重启服务器即可。</p>
<h2 id="HTTP协议"><a href="#HTTP协议" class="headerlink" title="HTTP协议"></a>HTTP协议</h2><p>http是用于规定浏览器和服务器通讯的方式/规范/规则</p>
<p>http协议工作的基本原则</p>
<ol>
<li>一次请求只对应一次响应</li>
<li>请求只能由浏览器发起，服务器只能被动等待，根据请求做出回应</li>
</ol>
<p><img src="http.png" alt="http"></p>
<h3 id="HTTP请求"><a href="#HTTP请求" class="headerlink" title="HTTP请求"></a>HTTP请求</h3><p><img src="http%E8%AF%B7%E6%B1%82.png" alt="request"></p>
<ul>
<li><ol>
<li>请求行</li>
</ol>
</li>
</ul>
<blockquote>
<p>GET  /news/hello.html  HTTP/1.1</p>
</blockquote>
<ol>
<li><p>GET：表示请求方式，在HTTP协议中一共定义了7种提交方式，但是我们只用GET和POST。</p>
</li>
<li><p>/news/hello.html：请求资源路径，表示浏览器请求的是哪一个Web应用以及哪一个web资源文件。</p>
</li>
<li><p>HTTP/1.1：请求所遵循的协议和版本。</p>
</li>
</ol>
<ul>
<li><ol start="2">
<li>若干请求头</li>
</ol>
</li>
</ul>
<p>请求头都是key-value结构：</p>
<blockquote>
<p>Host：localhost – 通知服务器，浏览器要请求的是哪一台虚拟主机。<br>Accept：text/html, application/xhtml+xml,…  – 通知服务器，浏览器能接收的响应数据类型。</p>
</blockquote>
<ul>
<li><ol start="3">
<li>请求实体内容</li>
</ol>
</li>
</ul>
<p>如果请求方式是GET提交，请求实体是没有内容的。如果请求方式为 POST 提交，并且请求中携带了数据，请求实体中才会有内容。</p>
<h3 id="HTTP响应"><a href="#HTTP响应" class="headerlink" title="HTTP响应"></a>HTTP响应</h3><p><img src="http%E5%93%8D%E5%BA%94.png" alt="response"></p>
<ul>
<li><ol>
<li>状态行</li>
</ol>
</li>
</ul>
<blockquote>
<p>HTTP/1.1 200 OK</p>
</blockquote>
<ul>
<li><p>(1) <code>HTTP/1.1</code>：表示响应所遵循的协议和版本</p>
</li>
<li><p>(2)<code>200</code>：状态码，三位数字，表示服务器对请求处理的结果</p>
</li>
</ul>
<blockquote>
<p>200: 表示请求处理成功</p>
<p>302: 表示请求重定向(即需要再进一步请求才可以获取到相应的资源)</p>
<p>304/307: 表示通知浏览器使用缓存</p>
<p>404: 表示浏览器请求的资源不存在(浏览器的问题, 请求路径错误)</p>
<p>500: 表示服务器在处理请求的过程中抛出了异常。</p>
</blockquote>
<ul>
<li>(3) <code>OK</code>：描述短语，表示服务器对请求处理的结果</li>
</ul>
<blockquote>
<p>200：OK</p>
<p>404：Not Found</p>
<p>500: Internal Server Error</p>
</blockquote>
<ul>
<li><ol start="2">
<li>若干响应头：也是key-value格式</li>
</ol>
</li>
</ul>
<blockquote>
<p>Content-Type: 表示服务器响应的数据类型，text/html,  image/*…</p>
<p>Content-Length: 表示服务器响应数据的长度, 例如: 384 /字节</p>
<p>Set-Cookie: 和cookie技术相关的一个头</p>
</blockquote>
<ul>
<li>3.响应实体内容</li>
</ul>
<p>响应实体就是浏览器所请求文件的内容。例如：浏览器向服务器请求一个hello.html文件，服务器会找到hello.html文件，将文件的内容作为响应实体发送给浏览器。</p>

    </div>

    
    
    

      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/05/15/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day17/" rel="prev" title="Java日拱一卒-day17">
      <i class="fa fa-chevron-left"></i> Java日拱一卒-day17
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/05/18/Java%E6%97%A5%E6%8B%B1%E4%B8%80%E5%8D%92-day19/" rel="next" title="Java日拱一卒-day19">
      Java日拱一卒-day19 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#tomcat服务器"><span class="nav-number">1.</span> <span class="nav-text">tomcat服务器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#目录介绍"><span class="nav-number">1.1.</span> <span class="nav-text">目录介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启动Tomcat"><span class="nav-number">1.2.</span> <span class="nav-text">启动Tomcat</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改默认端口"><span class="nav-number">1.3.</span> <span class="nav-text">修改默认端口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#HTTP协议"><span class="nav-number">2.</span> <span class="nav-text">HTTP协议</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#HTTP请求"><span class="nav-number">2.1.</span> <span class="nav-text">HTTP请求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTTP响应"><span class="nav-number">2.2.</span> <span class="nav-text">HTTP响应</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="文予"
      src="/uploads/wenyu.png">
  <p class="site-author-name" itemprop="name">文予</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">29</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文予</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> 强力驱动
  </div>


        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'forest',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

</body>
</html>
